const userinfo = {
  state:{
    name: '',
    login_status: '',   // 用户登录状态 0：未登录  1：已登录
  },
  getters:{
    name: state => {
      let name = state.name
      // console.log('name:' + name)
      // console.log(!name)
      if(!name){
        // console.log('local')
        name = window.localStorage.getItem('name')
      }
      return name
    },
    login_status: state => {
      let login_status = state.login_status
      if(!login_status){
        login_status = window.localStorage.getItem('login_status')
      }
      return login_status
    }
  },
  mutations:{
    setName: (state, name) => {
      state.name = name
      window.localStorage.setItem('name', name)
    },
    setLoginStatus: (state, login_status) => {
      state.login_status = login_status
      window.localStorage.setItem('login_status', login_status)
    }
  }
}

export default userinfo
